home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-25 | 30.0 KB | 1,479 lines |
- head 1.16;
- access;
- symbols
- RELEASE:1.16
- BETA:1.12;
- locks; strict;
- comment @ * @;
-
-
- 1.16
- date 91.06.21.12.51.15; author paul; state Exp;
- branches;
- next 1.15;
-
- 1.15
- date 91.06.20.19.17.29; author paul; state Exp;
- branches;
- next 1.14;
-
- 1.14
- date 91.06.13.19.55.52; author paul; state Exp;
- branches;
- next 1.13;
-
- 1.13
- date 91.06.05.17.18.27; author paul; state Exp;
- branches;
- next 1.12;
-
- 1.12
- date 91.06.01.22.18.25; author paul; state Exp;
- branches;
- next 1.11;
-
- 1.11
- date 91.05.29.19.32.55; author paul; state Exp;
- branches;
- next 1.10;
-
- 1.10
- date 91.05.23.21.33.42; author paul; state Exp;
- branches;
- next 1.9;
-
- 1.9
- date 91.04.05.14.55.15; author paul; state Exp;
- branches;
- next 1.8;
-
- 1.8
- date 91.03.28.20.43.17; author paul; state Exp;
- branches;
- next 1.7;
-
- 1.7
- date 91.03.28.18.19.52; author paul; state Exp;
- branches;
- next 1.6;
-
- 1.6
- date 91.03.22.05.13.53; author paul; state Exp;
- branches;
- next 1.5;
-
- 1.5
- date 91.03.05.21.38.22; author paul; state Exp;
- branches;
- next 1.4;
-
- 1.4
- date 91.01.10.22.25.33; author paul; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 90.11.29.10.46.24; author paul; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 90.11.26.21.13.35; author paul; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 90.11.19.16.11.54; author paul; state Exp;
- branches;
- next ;
-
-
- desc
- @Load Average code from the MIT X11R4 distribution. What goes around,
- comes around.
- @
-
-
- 1.16
- log
- @Apollos now use proc1_$get_loadav() which greatly simplified the routine.
- The previous code is wrapped in #ifdef notdef if needed. From Chrisos S.
- Zoulas (christos@@ee.cornell.edu).
- @
- text
- @/*
- * Copyright 1989 Massachusetts Institute of Technology
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of M.I.T. not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. M.I.T. makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
- * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors: Many and varied...
- */
-
- #ifndef lint
- static char sccs_id[] = "%W%";
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.15 1991/06/20 19:17:29 paul Exp paul $";
- #endif /* !lint */
-
- #include "conf.h"
-
- /* Necessary as AIX has a typedef for syserr [err.c] in sysinfo.h */
- #ifndef _AIX
- # include "sendmail.h"
- #endif /* !_AIX */
-
- #ifdef DGUX
- # include <sys/dg_sys_info.h>
-
- int getloadavg( call_data )
- caddr_t call_data; /* pointer to (double) return value */
- {
- struct dg_sys_info_load_info load_info;
-
- dg_sys_info(&load_info,
- DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
-
- *(double *)call_data = load_info.one_minute;
- }
- #else /* DGUX */
-
- # ifdef UMAX
- /*
- *
- * FOR: Encore multimax UMAX 4.3.
- *
- * Extracted from get_stats() (written by John Robert LoVerso)
- * by Neil Rickert.
- *
- * Use inq_stats() to determine boottime, load average
- *
- */
-
- # include <sys/param.h> /* */
- # include <inq_stats/statistics.h>
- # include <inq_stats/procstats.h>
-
- /*
- * see dimension of ps_nrun[] in procstats.h
- */
- # ifndef PS_NRUNSIZE
- # define PS_NRUNSIZE 300
- # endif
-
- /*
- * Each entry in ps_nrun[] is count of runnable processes sampled every
- * 5 seconds. period[] contains the number of samples to use for the
- * intervals of {1,5,15} minutes. cexp[] contains constans for exponential
- * decay.
- */
- # define period 12
-
- int getloadavg( call_data )
- caddr_t call_data; /* pointer to (double) return value */
- {
- struct stat_descr Proc_info;
- struct proc_summary Proc_sum_data;
- register int i, index, interval;
-
- /*
- * struct to get process summary data,
- * esp circular buffer containing counts of runnable processes
- */
- Proc_info.sd_next = NULL;
- Proc_info.sd_subsys = SUBSYS_PROC;
- Proc_info.sd_type = PROCTYPE_SUMMARY;
- Proc_info.sd_addr = (char *) &Proc_sum_data;
- Proc_info.sd_size = sizeof (struct proc_summary);
- Proc_info.sd_sizeused = 0;
-
- /*
- * fill in Boot_data and Proc_sum_data structures
- */
- if (inq_stats(1, &Proc_info) != 0) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: inq_stats(): %m");
- # endif /* LOG */
- return (-1);
- }
-
- /*
- * fastest (inverse shared sum) loop
- */
- index = Proc_sum_data.ps_nrunidx;
- interval = 0;
- *(double *)call_data = 0.0;
- for (; interval < period; interval++) {
- *(double *)call_data += Proc_sum_data.ps_nrun[index];
- if (--index < 0)
- index = PS_NRUNSIZE-1;
- }
-
- *(double *)call_data /= period;
- }
- # else /* UMAX */
-
- # ifdef _AIX
- /*
- * This version of this module (get_load.c) is specifically for the IBM
- * S/6000 AIX 3.1 platform. The copyright below applies to this module
- * only.
- *
- * Copyright (C) 1990 by the University of Illinois Board of Trustees.
- *
- * This code is distributed in the hope that it will be useful,
- * but without any warranty. No author or distributor accepts
- * responsibility to anyone for the consequences of using it or for
- * whether it serves any particular purpose or works at all, unless
- * s/he says so in writing.
- *
- * Author: Charley Kline, University of Illinois Computing Services
- * c-kline@@uiuc.edu
- *
- */
-
- # include <sys/sysinfo.h>
- # include <unistd.h>
- # include <fcntl.h>
- # include <syslog.h>
- # include <math.h>
- # include <nlist.h>
-
- struct nlist kernelnames[] = {
- {"sysinfo", 0, 0, 0, 0, 0},
- {NULL, 0, 0, 0, 0, 0},
- };
-
-
- /* ARGSUSED */
- int
- getloadavg (call_data)
- caddr_t call_data; /* pointer to (double) return value */
- {
- double *loadavg = (double *)call_data;
- double loadav;
- static double avenrun = 0.;
- struct sysinfo si;
- static int rq_old = 0, ro_old = 0;
- static initted = 0;
- static int fd;
- double multiplier;
- double t;
-
- /*
- * * Do stuff we only need to do once per invocation, like opening *
- * the kmem file and fetching the parts of the symbol table.
- */
- if (!initted) {
- initted = 1;
- knlist (kernelnames, 1, sizeof (struct nlist));
- if ((fd = open ("/dev/kmem", O_RDONLY)) < 0)
- {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: open /dev/kmem: %m");
- # endif /* LOG */
- return (-1);
- }
- }
- /*
- * * Get the system info structure from the running kernel.
- */
- lseek (fd, kernelnames[0].n_value, SEEK_SET);
- if (read (fd, (char *)&si, sizeof (struct sysinfo)) != sizeof (struct sysinfo))
- {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: read /dev/kmem: %m");
- # endif /* LOG */
- return (-1);
- }
-
- /*
- * AIX doesn't keep the load average variables in the kernel; all
- * we can get is the current number of runnable processes by
- * observing the difference between the runque and runocc values in
- * sysinfo. Having done this, however, we can apply a TENEX-style
- * exponential time-average to it by computing an averaging multiplier
- * based on the sampling interval. This is then used to factor in *
- * the current number of running processes to our running load
- * average. The result "looks right" when observed in conjunction
- * with the process table and user activity.
- *
- * We subtract one from the number of running processes given us by
- * the kernel because for some reason AIX always calls one of the
- * kernel processes "runnable" even though it uses very little CPU.
- * Subtracting this out gives a load average near zero when the
- * machine is mostly idle, which is more familiar to those of us who
- * are used to bsd-style load averages.
- */
- t = (double) (si.runocc - ro_old);
- loadav = (double) (si.runque - rq_old) / t - 1.0;
- rq_old = si.runque;
- ro_old = si.runocc;
- multiplier = exp (-t / 60.);
- avenrun = multiplier * avenrun + (1.0 - multiplier) * loadav;
- /*
- * DEBUG printf("%d %d %f %f %f\n", si.runque, si.runocc, t, loadav,
- * avenrun);
- */
-
- *loadavg = avenrun;
- return (0);
- }
- # else /* !_AIX */
-
- /*
- * Get open(2) constants
- */
- # ifdef SYSV
- # ifndef macII
- # include <fcntl.h>
- # endif /* !macII */
- # endif /* SYSV */
- # include <sys/file.h>
- # ifdef USG
- # include <unistd.h>
- # endif /* USG */
-
- # ifdef att
- # define LOADSTUB
- # endif /* att */
-
- # ifdef apollo
- # include <apollo/base.h>
- # include <apollo/time.h>
- # ifdef notdef
- typedef struct {
- short state; /* ready, waiting, etc. */
- pinteger usr; /* user sr */
- linteger upc; /* user pc */
- linteger usp; /* user stack pointer */
- linteger usb; /* user sb ptr (A6) */
- time_$clock_t cpu_total; /* cumulative cpu used by process */
- unsigned short priority; /* process priority */
- } proc1_$info_t;
-
- /* Enable function prototypes for ANSI C and C++ */
- # if (defined(__STDC__) || defined(c_plusplus) || defined(__cplusplus)) \
- && !defined(__GNUC__)
- # define _PROTOTYPES
- # endif /* (__STDC__ || c_plusplus || __cplusplus) && !__GNUC__ */
-
- void proc1_$get_cput(
- # ifdef _PROTOTYPES
- time_$clock_t *cput
- # endif /* _PROTOTYPES */
- );
-
- void proc1_$get_info(
- # ifdef _PROTOTYPES
- short &pid,
- proc1_$info_t *info,
- status_$t *sts
- # endif /* _PROTOTYPES */
- );
- # ifdef _PROTOTYPES
- # undef _PROTOTYPES
- # endif /* _PROTOTYPES */
-
- # endif /* notdef */
- # endif /* apollo */
-
- # if !defined(macII) && !defined(apollo) && !defined(LOADSTUB)
- # include <nlist.h>
- # endif /* !macII && !apollo && !LOADSTUB */
-
- # ifdef sun
- # include <sys/param.h>
- # ifdef i386
- # include <kvm.h>
- # define KVM_ROUTINES
- # endif /* i386 */
- # endif /* sun */
-
- # if defined(mips) && !defined(sgi)
- # include <sys/fixpoint.h>
- # endif /* mips && !sgi */
-
- # ifdef CRAY
- # include <sys/param.h>
- # include <sys/sysinfo.h>
- # undef n_type
- # define n_type n_value
- # endif /* CRAY */
-
- # ifdef vax
- # include <sys/param.h>
- # endif /* vax */
-
- # ifdef sequent
- # include <sys/vm.h>
- # endif /* sequent */
-
- # ifdef macII
- # include <a.out.h>
- # include <sys/var.h>
- # define X_AVENRUN 0
- # define fxtod(i) (vec[i].high+(vec[i].low/65536.0))
- struct lavnum {
- unsigned short high;
- unsigned short low;
- };
- # endif /* macII */
-
- # ifdef unixpc
- # define FSCALE 64.0
- # endif /* unixpc */
-
- # if defined(UTEK) || defined(alliant)
- # define FSCALE 100.0
- # endif /* UTEK || alliant */
-
- # if (defined(sequent) || defined(NeXT) || defined(sgi)) && !defined(FSCALE)
- # define FSCALE 1000.0
- # endif /* (sequent || NeXT || sgi) && !FSCALE */
-
- # ifdef hp9000
- # include <sys/param.h>
- # endif /* hp9000 */
-
- # ifndef FSCALE
- # define FSHIFT 8 /* bits to right of fixed binary point */
- # define FSCALE (1<<FSHIFT)
- # endif /* !FSCALE */
-
- # ifdef __STDC__
- extern off_t lseek(int, off_t, int);
- extern void exit(int);
- # else /* !__STDC__ */
- extern long lseek();
- extern void exit();
- # endif /* __STDC__ */
-
- # if apollo
- /* ARGSUSED */
- int getloadavg( call_data )
- caddr_t call_data; /* pointer to (double) return value */
- {
- # ifdef notdef
- static int firstTime = 1;
- static int lastNullCpu;
- static int lastClock;
- time_$clock_t timeNow;
- double temp;
- proc1_$info_t info;
- status_$t st;
-
- proc1_$get_info( (short) 2, &info, &st );
- time_$clock( &timeNow );
-
- if (firstTime)
- {
- *(double *)call_data = 1.0;
- firstTime = 0;
- }
- else {
- temp = info.cpu_total.low32 - lastNullCpu;
- *(double *)call_data = 1.0 - temp / (timeNow.low32 - lastClock);
- }
-
- lastClock = timeNow.low32;
- lastNullCpu = info.cpu_total.low32;
- return(0);
- # else /* !notdef */
- double *avenrun = (double *) call_data;
- int i;
- status_$t st;
- long loadav[3];
- proc1_$get_loadav(loadav, &st);
- *avenrun = loadav[0] / (double) (1 << 16);
- return(0);
- # endif /* notdef */
- }
- # else /* !apollo */
- # ifdef KVM_ROUTINES
- /*
- * Sun 386i Code - abstracted to see the wood for the trees
- */
-
- /* ARGSUSED */
- void
- getloadavg( call_data )
- caddr_t call_data; /* pointer to (double) return value */
- {
- double *loadavg = (double *)call_data;
- long temp;
- static int init = 0;
- static struct nlist nl[2];
- static kvm_t *kd;
-
- if (!init) {
- kd = kvm_open("/vmunix", NULL, NULL, O_RDONLY, NULL);
- if (kd == (kvm_t *)0) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: kvm_open /vmunix: %m");
- # endif /* LOG */
- return (-1);
- }
-
- nl[0].n_name = "avenrun";
- nl[1].n_name = NULL;
-
- if (kvm_nlist(kd, nl) != 0) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: kvm_nlist /vmunix: %m");
- # endif /* LOG */
- return (-1);
- }
- init = 1;
- }
-
- if (nl[0].n_value == 0) {
- return (-1);
- }
- if (kvm_read(kd, nl[0].n_value, (char *)&temp, sizeof (temp)) !=
- sizeof (temp)) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: kvm_read /vmunix: %m");
- # endif /* LOG */
- return (-1);
- }
- *loadavg = (double)temp/FSCALE;
- return(0);
- }
- # else /* !KVM_ROUTINES */
- # ifdef LOADSTUB
-
- /* ARGSUSED */
- int getloadavg( call_data )
- caddr_t call_data; /* pointer to (double) return value */
- {
- *(double *)call_data = 1.0;
- }
-
- # else /* !LOADSTUB */
-
- # ifndef KMEM_FILE
- # define KMEM_FILE "/dev/kmem"
- # endif /* !KMEM_FILE */
-
- # ifndef KERNEL_FILE
-
- # ifdef NeXT
- # define KERNEL_FILE "/mach"
- # endif /* NeXT */
-
- # ifdef alliant
- # define KERNEL_FILE "/unix"
- # endif /* alliant */
-
- # ifdef CRAY
- # define KERNEL_FILE "/unicos"
- # endif /* CRAY */
-
- # ifdef hpux
- # define KERNEL_FILE "/hp-ux"
- # endif /* hpux */
-
- # ifdef macII
- # define KERNEL_FILE "/unix"
- # endif /* macII */
-
- # ifdef mips
- # ifdef SYSTYPE_SYSV
- # define KERNEL_FILE "/unix"
- # else /* !SYSTYPE_SYSV */
- # define KERNEL_FILE "/vmunix"
- # endif /* SYSTYPE_SYSV */
- # endif /* mips */
-
- # ifdef sequent
- # define KERNEL_FILE "/dynix"
- # endif /* sequent */
-
- /*
- * provide default for everyone else
- */
- # ifndef KERNEL_FILE
- # ifdef SYSV
- # define KERNEL_FILE "/unix"
- # else /* !SYSV */
- # define KERNEL_FILE "/vmunix"
- # endif /* SYSV */
- # endif /* KERNEL_FILE */
- # endif /* KERNEL_FILE */
-
- # ifndef KERNEL_LOAD_VARIABLE
- /*
- * provide default
- */
- # ifdef USG
- # define KERNEL_LOAD_VARIABLE "sysinfo"
- # define SYSINFO
- # else /* !USG */
- # define KERNEL_LOAD_VARIABLE "_avenrun"
- # endif /* USG */
-
- # ifdef alliant
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "_Loadave"
- # endif /* alliant */
-
- # ifdef CRAY
- # if defined(CRAY2) && OSMAJORVERSION == 4
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # else /* !CRAY2 || OSMAJORVERSION != 4 */
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "sysinfo"
- # define SYSINFO
- # endif /* CRAY2 && OSMAJORVERSION == 4 */
- # endif /* CRAY */
-
- # ifdef hpux
- # ifdef hp9000s800
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # endif /* hp9000s800 */
- # endif /* hpux */
-
- # ifdef mips
- # ifdef SYSTYPE_SYSV
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # else /* !SYSTYPE_SYSV */
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "_avenrun"
- # endif /* SYSTYPE_SYSV */
- # endif /* mips */
-
- # ifdef unixpc
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # endif /* unixpc */
- # endif /* KERNEL_LOAD_VARIABLE */
-
- # ifdef macII
- struct var v;
- static int pad[2]; /* This padding is needed if getloadavg compiled on */
- /* a/ux 1.1 is executed on a/ux 1.0, because */
- /* the var structure had too much padding in 1.0, */
- /* so the 1.0 kernel writes past the end of the 1.1 */
- /* var structure in the uvar() call. */
- static struct nlist nl[2];
- static struct lavnum vec[3];
- # else /* not macII */
- static struct nlist namelist[] = { /* namelist for vmunix grubbing */
- # define LOADAV 0
- # ifdef NeXT
- {{KERNEL_LOAD_VARIABLE}},
- {{0},0}
- # else /* !NeXT */
- # ifdef unixpc
- { KERNEL_LOAD_VARIABLE, },
- { (char *)0, },
- # else /* !unixpc */
- {KERNEL_LOAD_VARIABLE},
- {0}
- # endif /* unixpc */
- # endif /* NeXT */
- };
- # endif /* macII */
-
-
- /* ARGSUSED */
- int getloadavg( call_data )
- caddr_t call_data; /* pointer to (double) return value */
- {
- double *loadavg = (double *)call_data;
- static int init = 0;
- static kmem;
- static long loadavg_seek;
- # ifdef macII
- # ifdef __STDC__
- extern int nlist(const char *, struct nlist *);
- # else /* !__STDC__ */
- extern int nlist();
- # endif /* __STDC__ */
-
- if(!init) {
- int i;
-
- (void) strcpy(nl[0].n_name, "avenrun");
- nl[1].n_name[0] = '\0';
-
- kmem = open(KMEM_FILE, O_RDONLY);
- if (kmem < 0) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: open %s: %m", KMEM_FILE);
- # endif /* LOG */
- return (-1);
- }
-
- uvar(&v);
-
- if (nlist( KERNEL_FILE, nl) != 0) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: nlist %s: %m", KERNEL_FILE);
- # endif /* LOG */
- return (-1);
- }
- for (i = 0; i < 2; i++) {
- nl[i].n_value = (int)nl[i].n_value - v.v_kvoffset;
- }
- init = 1;
- }
- # else /* !macII */
- # ifdef unixpc
- # ifdef __STDC__
- extern int nlist(const char *, struct nlist *);
- # else /* !__STDC__ */
- extern int nlist();
- # endif /* __STDC__ */
-
- if (!init)
- {
- if (nlist(KERNEL_FILE, namelist) != 0)
- return (-1);
- loadavg_seek = (long)namelist[0].n_value;
- if ((kmem = open(KMEM_FILE, O_RDONLY)) < 0)
- return (-1);
- init = 1;
- }
- # else /* !unixpc */
- # if !defined(sgi) && !defined(BSD4_4)
- extern void nlist();
- # else /* sgi || BSD4_4 */
- extern nlist();
- # endif /* !sgi && !BSD4_4 */
-
- if(!init) {
- nlist( KERNEL_FILE, namelist);
- /*
- * Some systems appear to set only one of these to Zero if the entry could
- * not be found, I hope no_one returns Zero as a good value, or bad things
- * will happen to you. (I have a hard time believing the value will
- * ever really be zero anyway). CDP 5/17/89.
- */
- if (namelist[LOADAV].n_type == 0 ||
- namelist[LOADAV].n_value == 0) {
- return (-1);
- }
- loadavg_seek = namelist[LOADAV].n_value;
- # if defined(mips) && defined(SYSTYPE_SYSV)
- loadavg_seek &= 0x7fffffff;
- # endif /* mips && SYSTYPE_SYSV */
- # if defined(CRAY) && defined(SYSINFO)
- loadavg_seek += ((char *) (((struct sysinfo *)NULL)->avenrun)) -
- ((char *) NULL);
- # endif /* CRAY && SYSINFO */
-
- kmem = open(KMEM_FILE, O_RDONLY);
- if (kmem < 0) {
- # ifdef LOG
- syslog(LOG_WARNING, "getloadavg: open %s: %m", KMEM_FILE);
- # endif /* LOG */
- return (-1);
- }
- init = 1;
- }
- # endif /* unixpc */
- (void) lseek(kmem, loadavg_seek, 0);
- # endif /* macII */
- # if defined(sun) || defined (UTEK) || defined(sequent) || \
- defined(alliant) || defined(hp9000) || defined(sgi) || defined(NeXT) || \
- defined(unixpc)
- {
- long temp;
- (void) read(kmem, (char *)&temp, sizeof(long));
- *loadavg = (double)temp/FSCALE;
- }
- # else /* !sun && !UTEK && !sequent && !alliant && !hp9000 && !sgi && !NeXT && !unixpc */
- # ifdef macII
- {
- lseek(kmem, (long)nl[X_AVENRUN].n_value, 0);
- read(kmem, vec, 3*sizeof(struct lavnum));
- *loadavg = fxtod(0);
- }
- # else /* !macII */
- # if defined(mips)
- {
- fix temp;
- (void) read(kmem, (char *)&temp, sizeof(fix));
- *loadavg = FIX_TO_DBL(temp);
- }
- # else /* !mips */
- (void) read(kmem, (char *)loadavg, sizeof(double));
- # endif /* mips */
- # endif /* macII */
- # endif /* sun || UTEK || sequent || alliant || hp9000 || sgi || NeXT || unixpc */
- return(0);
- }
- # endif /* LOADSTUB */
- # endif /* KVM_ROUTINES */
- # endif /* apollo */
- # endif /* _AIX */
- # endif /* UMAX */
- #endif /* DGUX */
- @
-
-
- 1.15
- log
- @ANSI C changes for unixpc.
- @
- text
- @d26 1
- a26 1
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.14 1991/06/13 19:55:52 paul Exp paul $";
- d254 1
- d266 4
- a269 3
- # if defined(__STDC__) || defined(c_plusplus) || defined(__cplusplus)
- # define _PROTOTYPES
- # endif
- d272 1
- a272 1
- # ifdef _PROTOTYPES
- d274 1
- a274 1
- # endif /* _PROTOTYPES */
- d278 1
- a278 1
- # ifdef _PROTOTYPES
- d282 1
- a282 1
- # endif /* _PROTOTYPES */
- d284 3
- a286 3
- # ifdef _PROTOTYPES
- # undef _PROTOTYPES
- # endif /* _PROTOTYPES */
- d288 1
- d367 1
- d392 9
- @
-
-
- 1.14
- log
- @unixpc patch.
- @
- text
- @d26 1
- a26 1
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.13 1991/06/05 17:18:27 paul Exp paul $";
- d351 4
- d357 1
- d589 5
- a593 1
- extern nlist();
- d624 5
- a628 3
- extern int nlist();
- extern int open();
- extern int read();
- @
-
-
- 1.13
- log
- @Fix for SGI.
- @
- text
- @d26 1
- a26 1
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.12 1991/06/01 22:18:25 paul Exp paul $";
- d665 1
- a665 1
-
- a666 1
- # endif /* unixpc */
- @
-
-
- 1.12
- log
- @De-linting (omitted voids).
- @
- text
- @d26 1
- a26 1
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.11 1991/05/29 19:32:55 paul Exp paul $";
- d338 1
- a338 1
- # if (defined(sequent) || defined(NeXT)) && !defined(FSCALE)
- d340 1
- a340 1
- # endif /* (sequent || NeXT) && !FSCALE */
- @
-
-
- 1.11
- log
- @Load average code for the AT&T unix pc from Bruce Lilly.
- @
- text
- @d26 1
- a26 1
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.10 1991/05/23 21:33:42 paul Exp paul $";
- d589 1
- a589 1
- strcpy(nl[0].n_name, "avenrun");
- @
-
-
- 1.10
- log
- @Now includes conf.h and, if not an AIX box that defines syserr as something
- else, sendmail.h. This is necessary for moving compilation defines from
- the command line into config files.
- @
- text
- @d25 2
- a26 1
- static char rcsid[] = "@@(#)$Id: getloadavg.c,v 1.9 1991/04/05 14:55:15 paul Exp paul $";
- d201 5
- a205 5
- * * AIX doesn't keep the load average variables in the kernel; all *
- * we can get is the current number of runnable processes by *
- * observing the difference between the runque and runocc values * in
- * sysinfo. Having done this, however, we can apply a TENEX-style *
- * exponential time-average to it by computing an averaging multiplier *
- d208 2
- a209 2
- * average. * The result "looks right" when observed in conjunction
- * with the * process table and user activity. *
- d211 3
- a213 3
- * We subtract one from the number of running processes given us by *
- * the kernel because for some reason AIX always calls one of the *
- * kernel processes "runnable" even though it uses very little CPU. *
- d215 2
- a216 2
- * machine * is mostly idle, which is more familiar to those of us who
- * are * used to bsd-style load averages.
- d330 4
- d541 4
- a544 3
- # ifdef sequent
- # define KERNEL_FILE "/dynix"
- # endif /* sequent */
- d563 4
- d569 1
- d614 16
- a629 1
- # if !defined(sgi) && !defined(BSD4_4)
- d631 1
- a631 1
- # else /* sgi || BSD4_4 */
- d633 1
- a633 1
- # endif /* !sgi && !BSD4_4 */
- d648 1
- a648 1
- # if defined(mips) && defined(SYSTYPE_SYSV)
- d650 2
- a651 2
- # endif /* mips && SYSTYPE_SYSV */
- # if defined(CRAY) && defined(SYSINFO)
- d654 1
- a654 1
- # endif /* CRAY && SYSINFO */
- d658 1
- a658 1
- # ifdef LOG
- d660 1
- a660 1
- # endif /* LOG */
- d667 1
- d670 2
- a671 1
- defined(alliant) || defined(hp9000) || defined(sgi) || defined(NeXT)
- d677 1
- a677 1
- # else /* !sun && !UTEK && !sequent && !alliant && !hp9000 && !sgi && !NeXT */
- d695 1
- a695 1
- # endif /* sun || UTEK || sequent || alliant || hp9000 || sgi || NeXT */
- @
-
-
- 1.9
- log
- @Added RCS ID string
- @
- text
- @d25 1
- a25 1
- static char rcsid[] = "@@(#)$Id$";
- d28 7
- a34 1
- #include <sys/types.h>
- a62 1
- # include <sys/time.h> /* */
- a144 1
- # include <sys/types.h>
- d147 1
- @
-
-
- 1.8
- log
- @Added AIX load averaging code, cleaned up # indents.
- @
- text
- @d17 1
- a17 2
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
- AN ACTION
- d23 4
- @
-
-
- 1.7
- log
- @Fixed for NeXT.
- @
- text
- @d27 1
- a27 1
- #include <sys/dg_sys_info.h>
- d41 1
- a41 1
- #ifdef UMAX
- d53 4
- a56 4
- #include <sys/param.h> /* */
- #include <sys/time.h> /* */
- #include <inq_stats/statistics.h>
- #include <inq_stats/procstats.h>
- d61 3
- a63 3
- #ifndef PS_NRUNSIZE
- #define PS_NRUNSIZE 300
- #endif
- d71 1
- a71 1
- #define period 12
- d95 4
- a98 2
- perror("inq_stats");
- exit(1);
- d115 109
- a223 1
- #else /* UMAX */
- d228 17
- a244 17
- #ifdef SYSV
- #ifndef macII
- #include <fcntl.h>
- #endif
- #endif /* SYSV */
- #include <sys/file.h>
- #ifdef USG
- #include <unistd.h>
- #endif
-
- #ifdef att
- #define LOADSTUB
- #endif
-
- #ifdef apollo
- #include <apollo/base.h>
- #include <apollo/time.h>
- d256 3
- a258 3
- #if defined(__STDC__) || defined(c_plusplus) || defined(__cplusplus)
- # define _PROTOTYPES
- #endif
- d261 1
- a261 1
- #ifdef _PROTOTYPES
- d263 1
- a263 1
- #endif
- d267 1
- a267 1
- #ifdef _PROTOTYPES
- d271 1
- a271 1
- #endif
- d273 5
- a277 13
- #ifdef _PROTOTYPES
- # undef _PROTOTYPES
- #endif
-
- #endif /* apollo */
-
- #ifndef macII
- #ifndef apollo
- #ifndef LOADSTUB
- #include <nlist.h>
- #endif /* LOADSTUB */
- #endif /* apollo */
- #endif /* macII */
- d279 5
- a283 1
- #ifdef sun
- d286 2
- a287 2
- # include <kvm.h>
- # define KVM_ROUTINES
- d289 5
- a293 1
- #endif
- d295 20
- a314 24
- #if defined(mips) && !defined(sgi)
- #include <sys/fixpoint.h>
- #endif
-
- #ifdef CRAY
- #include <sys/param.h>
- #include <sys/sysinfo.h>
- #undef n_type
- #define n_type n_value
- #endif /* CRAY */
-
- #ifdef vax
- #include <sys/param.h>
- #endif /* sequent */
-
- #ifdef sequent
- #include <sys/vm.h>
- #endif /* sequent */
-
- #ifdef macII
- #include <a.out.h>
- #include <sys/var.h>
- #define X_AVENRUN 0
- #define fxtod(i) (vec[i].high+(vec[i].low/65536.0))
- d319 5
- a323 1
- #endif /* macII */
- d325 3
- a327 16
- #if defined(UTEK) || defined(alliant)
- #define FSCALE 100.0
- #endif
-
- #if (defined(sequent) || defined(NeXT)) && !defined(FSCALE)
- #define FSCALE 1000.0
- #endif
-
- #ifdef hp9000
- #include <sys/param.h>
- #endif
-
- #ifndef FSCALE
- #define FSHIFT 8 /* bits to right of fixed binary point */
- #define FSCALE (1<<FSHIFT)
- #endif /* not FSCALE */
- d329 9
- d341 1
- a341 1
- #if apollo
- d371 2
- a372 2
- #else
- #ifdef KVM_ROUTINES
- d391 3
- d401 3
- d414 3
- d422 2
- a423 2
- #else /* KVM_ROUTINES */
- #ifdef LOADSTUB
- d432 35
- a466 1
- #else /* LOADSTUB */
- d468 3
- a470 37
- #ifndef KMEM_FILE
- #define KMEM_FILE "/dev/kmem"
- #endif
-
- #ifndef KERNEL_FILE
-
- #ifdef NeXT
- #define KERNEL_FILE "/mach"
- #endif /* NeXT */
-
- #ifdef alliant
- #define KERNEL_FILE "/unix"
- #endif /* alliant */
-
- #ifdef CRAY
- #define KERNEL_FILE "/unicos"
- #endif /* CRAY */
-
- #ifdef hpux
- #define KERNEL_FILE "/hp-ux"
- #endif /* hpux */
-
- #ifdef macII
- #define KERNEL_FILE "/unix"
- #endif /* macII */
-
- #ifdef mips
- # ifdef SYSTYPE_SYSV
- # define KERNEL_FILE "/unix"
- # else
- # define KERNEL_FILE "/vmunix"
- # endif /* SYSTYPE_SYSV */
- #endif /* mips */
-
- #ifdef sequent
- #define KERNEL_FILE "/dynix"
- #endif /* sequent */
- d475 8
- a482 8
- #ifndef KERNEL_FILE
- #ifdef SYSV
- #define KERNEL_FILE "/unix"
- #else
- #define KERNEL_FILE "/vmunix"
- #endif /* SYSV */
- #endif /* KERNEL_FILE */
- #endif /* KERNEL_FILE */
- d484 1
- a484 1
- #ifndef KERNEL_LOAD_VARIABLE
- d488 1
- a488 1
- # ifdef USG
- d491 1
- a491 1
- # else
- d493 1
- a493 1
- # endif
- d495 1
- a495 1
- # ifdef alliant
- d498 1
- a498 1
- # endif /* alliant */
- d500 1
- a500 1
- # ifdef CRAY
- d502 15
- a516 15
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # else
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "sysinfo"
- # define SYSINFO
- # endif /* defined(CRAY2) && OSMAJORVERSION == 4 */
- # endif /* CRAY */
-
- # ifdef hpux
- # ifdef hp9000s800
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # endif /* hp9000s800 */
- # endif /* hpux */
- d518 9
- a526 9
- # ifdef mips
- # ifdef SYSTYPE_SYSV
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "avenrun"
- # else
- # undef KERNEL_LOAD_VARIABLE
- # define KERNEL_LOAD_VARIABLE "_avenrun"
- # endif /* SYSTYPE_SYSV */
- # endif /* mips */
- d528 4
- a531 4
- # ifdef sequent
- # define KERNEL_FILE "/dynix"
- # endif /* sequent */
- #endif /* KERNEL_LOAD_VARIABLE */
- d533 1
- a533 1
- #ifdef macII
- d542 1
- a542 1
- #else /* not macII */
- d544 2
- a545 2
- #define LOADAV 0
- # ifdef NeXT
- d548 1
- a548 1
- # else /* !NeXT */
- d551 1
- a551 1
- # endif /* NeXT */
- d553 1
- a553 1
- #endif /* macII */
- d564 1
- a564 1
- #ifdef macII
- d575 3
- d584 3
- d594 2
- a595 2
- #else /* not macII */
- # if !defined(sgi) && !defined(BSD4_4)
- d597 1
- a597 1
- # else
- d599 2
- a600 2
- # endif /* !sgi */
-
- d614 1
- a614 1
- #if defined(mips) && defined(SYSTYPE_SYSV)
- d616 2
- a617 2
- #endif /* mips && SYSTYPE_SYSV */
- #if (defined(CRAY) && defined(SYSINFO))
- d620 2
- a621 2
- #endif /* SYSINFO */
-
- d623 4
- a626 1
- if (kmem < 0)
- d628 1
- a630 1
-
- d633 3
- a635 3
- #endif /* macII */
- #if defined(sun) || defined (UTEK) || defined(sequent) || \
- defined(alliant) || defined(hp9000) || defined(sgi) || defined(NeXT)
- d641 2
- a642 2
- #else /* else not sun */
- # ifdef macII
- d648 2
- a649 2
- # else /* else not macII */
- # if defined(mips)
- d655 1
- a655 1
- # else /* not mips */
- d657 3
- a659 3
- # endif /* mips */
- # endif /* macII */
- #endif /* sun */
- d662 5
- a666 4
- #endif /* LOADSTUB */
- #endif /* KVM_ROUTINES */
- #endif /* apollo */
- #endif /* UMAX */
- @
-
-
- 1.6
- log
- @Multimax load average code.
- @
- text
- @d219 1
- a219 1
- #if defined(sequent) && !defined(FSCALE)
- d325 4
- d511 1
- a511 1
- defined(alliant) || defined(hp9000) || defined(sgi)
- @
-
-
- 1.5
- log
- @Apollo changes for -A nansi.
- @
- text
- @d41 1
- d43 73
- d537 1
- @
-
-
- 1.4
- log
- @Updated for 4.3 BSD-reno.
- @
- text
- @d71 5
- d77 1
- d79 1
- d83 1
- d87 1
- d89 4
- @
-
-
- 1.3
- log
- @Fixes for SGI Iris and Next machines.
- @
- text
- @d109 4
- d383 1
- a383 1
- # ifndef sgi
- @
-
-
- 1.2
- log
- @Fixed apollo case.
- @
- text
- @d98 1
- a98 1
- #ifdef mips
- d128 1
- a128 1
- #ifdef sequent
- d136 5
- d335 4
- d341 1
- d379 1
- d381 3
- d416 1
- a416 1
- defined(alliant) || defined(hp9000)
- d430 1
- a430 1
- # ifdef mips
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d144 1
- a144 1
- static Bool firstTime = TRUE;
- d158 1
- a158 1
- firstTime = FALSE;
- @
-